import * as React from 'react';
import * as qs from 'qs';
import {RouteComponentProps} from "react-router";

export interface OAuthLoginCallbackProps {

}

class OAuthLoginCallback extends React.Component<OAuthLoginCallbackProps & RouteComponentProps, any> {
  static defaultProps = {};

  componentDidMount() {
    const {location, match} = this.props;
    const data = qs.parse(location.search.slice(1));
    if (!data.code) {
      if (location.hash.length) {
        const data = qs.parse(location.search.slice(1));
        if (!data) {
          console.log(data)
          return;
        }
      }
      return;
    }


    fetch('http://open.zzht.cursor.io/?w=userLogin', {
      method: 'post',
      body: JSON.stringify({
        code: data.code,
      }),
      headers: {
        'content-type': 'application/json',
      }
    }).then(res => res.json())
      .then(res => {
        console.log('登录成功')
        console.log(res);
      }).catch(e => {
      console.log(e);
    })
  }

  private authorizeLogin() {
  }

  private goHome() {
    console.log('Home ')
  }

  private isLogin() {
    return false;
  }

  render() {
    return null;
  }
}

export default OAuthLoginCallback;
